package com.dc.aimc.common.mqtt.subscribe;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.stereotype.Component;


/**
 * @Date: 2021/4/21 下午 5:37
 * @Author: 冯照龙
 * @Description: mqtt订阅消息处理
 * @Version: 1.0
 */
@Component
public class MqttSubscriber implements MessageHandler {

    /**
     * 消息处理器
     */
    @Autowired(required = false)
    private MessageDisposer disposer;

    @Override
    public void handleMessage(Message<?> message) {
        String topic = String.valueOf(message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC));
        String data = String.valueOf(message.getPayload());
        if (disposer != null) disposer.dispose(topic, data);
    }

}
